<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

/**
 * App\Models\ConfigStorm
 *
 * @property int $id
 * @property array|null $rest_weekdays
 * @property int $is_gold_support_open
 * @property string $gold_support_beans
 * @property string $gold_support_coins
 * @property string $gold_support_cashes
 * @property string $a_gold_bean_buy_cashes
 * @property int $each_upgrade_needs_children
 * @property string $allowed_lowest_transfer_gold_beans
 * @property string $allowed_transfer_gold_beans_multiple
 * @property string $allowed_lowest_transfer_gold_coins
 * @property string $round_premium_percent
 * @property string $resell_need_beans_percent
 * @property string $move_round_profit_percent
 * @property string $last_round_profit_percent
 * @property int $gold_split_resell_period
 * @property string $child_first_record_give_direct_parent_cashes
 * @property string $child_record_give_direct_parent_master_prize_percent
 * @property string $child_record_give_direct_parent_intern_prize_percent
 * @property string $child_record_give_team_parent_masters_prize_percent
 * @property int $child_record_give_team_parent_masters_amount
 * @property int $pay_code_can_try
 * @property int $pay_gold_record_must_within_minutes
 * @property int $take_back_gold_product_within_minutes
 * @property int $terminate_gold_product_within_minutes
 * @property bool $is_robot_on
 * @property bool $is_reclaim_on
 * @property bool $is_terminate_on
 * @method static \Database\Factories\ConfigStormFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm query()
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereAGoldBeanBuyCashes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereAllowedLowestTransferGoldBeans($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereAllowedLowestTransferGoldCoins($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereAllowedTransferGoldBeansMultiple($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereChildFirstRecordGiveDirectParentCashes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereChildRecordGiveDirectParentInternPrizePercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereChildRecordGiveDirectParentMasterPrizePercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereChildRecordGiveTeamParentMastersAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereChildRecordGiveTeamParentMastersPrizePercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereEachUpgradeNeedsChildren($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereGoldSplitResellPeriod($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereGoldSupportBeans($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereGoldSupportCashes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereGoldSupportCoins($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereIsGoldSupportOpen($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereIsReclaimOn($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereIsRobotOn($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereIsTerminateOn($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereLastRoundProfitPercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereMoveRoundProfitPercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm wherePayCodeCanTry($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm wherePayGoldRecordMustWithinMinutes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereResellNeedBeansPercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereRestWeekdays($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereRoundPremiumPercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereTakeBackGoldProductWithinMinutes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereTerminateGoldProductWithinMinutes($value)
 * @mixin \Eloquent
 * @property int $gold_wastes_order_period
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereGoldWastesOrderPeriod($value)
 * @property bool $is_overcome_pay_fine
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigStorm whereIsOvercomePayFine($value)
 */
class ConfigStorm extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

	protected $casts = [
        'rest_weekdays'         => 'json',
		'is_overcome_pay_fine' 	=> 'boolean',
		'is_robot_on' 	        => 'boolean',
		'is_reclaim_soon' 	    => 'boolean',
		'is_reclaim_on' 	    => 'boolean',
		'is_terminate_on' 	    => 'boolean',
	];

    public $timestamps = false;

    public static function cache()
    {
    	if (Cache::has('config_storm')) {
    		return Cache::get('config_storm');
	    } else {
    		self::find(1)->addToCache();
		    return Cache::get('config_storm');
	    }
    }

    public function addToCache()
    {
    	$data = [
    		'is_gold_support_open' => $this->is_gold_support_open,
		    'gold_support_beans' => $this->gold_support_beans,
		    'gold_support_coins' => $this->gold_support_coins,
		    'gold_support_cashes' => $this->gold_support_cashes,
		    'a_gold_bean_buy_cashes' => $this->a_gold_bean_buy_cashes,

		    'each_upgrade_needs_children' => $this->each_upgrade_needs_children,
		    'allowed_highest_upgrade_level' => $this->allowed_highest_upgrade_level,
		    'allowed_lowest_transfer_gold_beans' => $this->allowed_lowest_transfer_gold_beans,
		    'allowed_transfer_gold_beans_multiple' => $this->allowed_transfer_gold_beans_multiple,
		    'allowed_lowest_transfer_gold_coins' => $this->allowed_lowest_transfer_gold_coins,

		    'round_premium_percent' => $this->round_premium_percent,
		    'resell_need_beans_percent' => $this->resell_need_beans_percent,
		    'move_round_profit_percent' => $this->move_round_profit_percent,
		    'last_round_profit_percent' => $this->last_round_profit_percent,
		    'gold_split_resell_period' => $this->gold_split_resell_period,

            'child_first_record_give_direct_parent_cashes' => $this->child_first_record_give_direct_parent_cashes,
            'child_record_give_direct_parent_master_prize_percent' => $this->child_record_give_direct_parent_master_prize_percent,
            'child_record_give_direct_parent_intern_prize_percent' => $this->child_record_give_direct_parent_intern_prize_percent,

            'child_record_give_team_parent_masters_prize_percent' => $this->child_record_give_team_parent_masters_prize_percent,
            'child_record_give_team_parent_masters_amount' => $this->child_record_give_team_parent_masters_amount,

		    'pay_code_can_try' => $this->pay_code_can_try,
            'is_overcome_pay_fine' => $this->is_overcome_pay_fine,
		    'pay_gold_record_must_within_minutes' => $this->pay_gold_record_must_within_minutes,
		    'take_back_gold_product_within_minutes' => $this->take_back_gold_product_within_minutes,
		    'terminate_gold_product_within_minutes' => $this->terminate_gold_product_within_minutes,

		    'is_robot_on' => $this->is_robot_on,
		    'is_reclaim_on' => $this->is_reclaim_on,
		    'is_terminate_on' => $this->is_terminate_on,
            'examine_expire_minuts' => $this->examine_expire_minuts,
	    ];

    	Cache::put('config_storm', $data);
    }
}
